package hot100.logos41To50;

import hot100.datastruct.TreeNode;

/**
 * @author logos
 * date 2025/7/14 12:22
 * @version v1.0
 * @Package hot100.logos41To50
 */
public class logos46 {

    /**
     * 46. 二叉搜索树展开为链表
     * https://leetcode.cn/problems/flatten-binary-tree-to-linked-list/?envType=study-plan-v2&envId=top-100-liked
     */

    class Solution {
        public void flatten(TreeNode root) {
            if (root == null) {
                return;
            }
            flatten(root.left);
            flatten(root.right);
            TreeNode tmp = root.right;
            root.right = root.left;
            root.left = null;
            while (root.right != null) {
                root = root.right;
            }
            root.right = tmp;
        }
    }
}
